import numpy as np
import platgo as pg

"""
Modified Tchebycheff approach
Reference:
https://github.com/BIMK/PlatEMO/blob/master/PlatEMO/Algorithms/MOEA-D/MOEAD.m
"""


def tche_modify(pop: pg.Population, weights: np.ndarray, Z: np.ndarray) -> np.ndarray:
    """
    修正的切比雪夫权重分解
    :param pop:
    :param weights:
    :param Z: 理想点
    :return: 返回权重聚合后的目标函数值, shape=(T,)
    """
    objv = pop.objv
    ans = np.max((objv - Z) / weights, axis=1)
    return ans
